<template>
  <div class="dialog">
    <el-dialog
      title="查看图片"
      :visible.sync="showDialog"
      width="50%"
      top="0"
      :close-on-click-modal="false"
      @close="cancel"
    >
      <div class="image">
        <el-image v-if="!!pictureUrl" :src="pictureUrl">
          <!-- :preview-src-list="srcList" -->
          <div slot="error" class="image-slot">
            <i class="el-icon-picture-outline"></i>
          </div>
        </el-image>
        <div v-else>未上传图片</div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button class="cancelbtn" @click="cancel()">取 消</el-button>
        <!-- <el-button type="primary" class="savebtn" @click="cancel()">确 定</el-button> -->
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "AddEditdialogImg",
  components: {},
  props: {
    // 弹框名称
    titleText: {
      type: String,
      default: ""
    },
    show: {
      type: Boolean,
      default: false
    },
    pictureUrl: {
      type: String,
      default: ""
    }
  },
  data() {
    return {
      srcList: [],
      showDialog: this.show,
      // 展示
      formData: {
        img: "",
        equipmentName: "",
        operationMode: ""
      },
      pictureList: [],
      options: [
        {
          value: "选项1",
          label: "黄金糕"
        },
        {
          value: "选项2",
          label: "双皮奶"
        }
      ],
      devs: ["测试1", "测试2"],
      rules: {
        equipmentName: [
          {
            required: true,
            message: "请输入报告图片",
            trigger: ["change", "blur"]
          }
        ],
        equipmentName1: [
          {
            required: true,
            message: "请输入上传人",
            trigger: ["change", "input", "blur"]
          }
        ],
        equipmentName3: [
          {
            required: true,
            message: "请输入上传时间",
            trigger: ["change", "blur"]
          }
        ]
      }
    };
  },

  watch: {
    show(v) {
      this.showDialog = v;
    },
    pictureUrl(v) {
      this.srcList = [];
      this.srcList.push(v);
    }
  },
  created() {},
  mounted() {},
  methods: {
    add() {
      this.devs.push("测试3");
    },
    save(formData) {
      this.$refs[formData].validate(valid => {
        if (valid) {
          console.log(this.formData);
        }
      });
    },
    close() {
      this.$emit("closeDialog");
    },
    cancel() {
      this.$emit("closeDialog");
      this.formData = {};
    }
  }
};
</script>

<style lang="scss" scoped>
.image {
  width: 100%;
  height: 400px;
  text-align: center;
  font-size: 18px;
  display: flex;
  flex-direction: row; /* 子元素横向排列 */
  justify-content: center; /* 相对父元素水平居中 */
  align-items: center;
}
</style>
